<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>4/6</title>
		<style type="text/css">
			* {
				padding: 0;
				margin: 0;
			}
			
			.container {
				width: 100vw;
				height: 100vh;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			
			canvas {
				width: 500px;
				height: 500px;
				border: 2px solid blue;
			}
		</style>
	</head>

	<body>
		<div id="answer"></div>
		<div class="container">
			<canvas id="canvas" width="500" height="500"></canvas>
		</div>
	</body>
	<script type="text/javascript">
		window.onload = function() {
			let oCanvas = document.getElementById('canvas');

			console.dir(oCanvas);

			let oPen = oCanvas.getContext("2d");

			console.dir(oPen);
            //lineCap 定义线条开始处和结尾处的线帽样式
			oPen.beginPath();
			oPen.lineWidth=30;
			oPen.moveTo(20, 20);
			oPen.lineCap = "round";
			oPen.lineTo(20, 200);
			oPen.stroke();
			
			oPen.beginPath();
			oPen.lineWidth=30;
			oPen.moveTo(70, 20);
			oPen.lineCap = "square";
			oPen.lineTo(70, 200);
			oPen.stroke();
			
			oPen.beginPath();
			oPen.lineWidth=30;
			oPen.moveTo(120, 20);
			oPen.lineCap = "butt";
			oPen.lineTo(120, 200);
			oPen.stroke();
			
			//lineJion 当线交接时的样式
			// miter（默认值，尖角）  round（圆角）  bevel（斜角）
			
			oPen.beginPath();
			oPen.lineWidth=20;
			oPen.lineJoin="round";
			oPen.moveTo(180,10);
			oPen.lineTo(250,10);
			oPen.lineTo(180,100);
			oPen.stroke();
			
			oPen.beginPath();
			oPen.lineWidth=20;
			oPen.lineJoin="miter";
			oPen.moveTo(300,10);
			oPen.lineTo(380,10);
			oPen.lineTo(300,100);
			oPen.stroke();
			
			oPen.beginPath();
			oPen.lineWidth=20;
			oPen.lineJoin="bevel";
			oPen.moveTo(220,120);
			oPen.lineTo(340,120);
			oPen.lineTo(220,220);
			oPen.stroke();
			
			//setLineDash 定义线条的虚实样式
			// 定义的数组指的是（从前往后） 虚线宽度（粗细），间距      []里增加数字即循环
			let myArray=[4,5];
			oPen.strokeStyle="red";
			oPen.lineWidth=7;
			oPen.setLineDash(myArray);
			oPen.strokeRect(100,280,150,100);
		}
	</script>
	</body>

</html>